

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <stack>

#include "common/utils.hpp"

int sumOfLeftLeaves(TreeNode* root) {
    std::queue<TreeNode*> que;
    if (root != nullptr) que.push(root);
    int ret = 0;

    while(!que.empty()) {
        TreeNode* node = que.front();
        que.pop();
        // node->left是叶子节点
        if (node->left != nullptr && node->left->left == nullptr && node->left->right == nullptr) {
            ret += node->left->val;
        }
        if (node->left != nullptr) que.push(node->left);
        if (node->right != nullptr) que.push(node->right);
    }

    return ret;
}

extern TreeNode* commonRoot;

int main() {
    int ret = sumOfLeftLeaves(commonRoot);
    std::cout << "res: " << ret << "\n";
}